package com.example.glblend;

import android.opengl.GLES20;

public class Image {

    private VertexArray vertexArray;

    private final int POSITION_COMPONENT_COUNT = 2;

    private final int TEXTURE_COMPONENT_COUNT = 2;

    private final int STRIDE = (POSITION_COMPONENT_COUNT + TEXTURE_COMPONENT_COUNT) * 4;

    public Image() {
        vertexArray = new VertexArray(new float[] {
                -1,  1,  0,  0,
                 1,  1,  1,  0,
                -1, -1,  0,  1,

                 1,  1,  1,  0,
                -1, -1,  0,  1,
                 1, -1,  1,  1,
        });
    }

    public void bindData(ImageShaderProgram imageShaderProgram) {
        int dataOffset = 0;

        vertexArray.setVertexAttribPointer(dataOffset,
                imageShaderProgram.getaPosition(),
                POSITION_COMPONENT_COUNT, STRIDE);

        dataOffset += POSITION_COMPONENT_COUNT;
        vertexArray.setVertexAttribPointer(dataOffset,
                imageShaderProgram.getA_TextureCoord(),
                TEXTURE_COMPONENT_COUNT, STRIDE);
    }

    public void draw() {
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
    }
}
